<template>
  <view class="container">
    <view class="container-mask" :class="{ show: showPop }" @tap="showPop = false"></view>
    <view class="container-pop" :class="{ show: showPop }">
      <view>筛选</view>
      <view class="row">
        <view class="left">开始时间</view>
        <view class="right" @click="showStartDate = true"> <u-input class="my-input" v-model="startTime" placeholder="请选择" readonly></u-input></view>
      </view>
      <view class="row">
        <view class="left">结束时间</view>
        <view class="right" @click="showEndDate = true"> <u-input class="my-input" v-model="endTime" placeholder="请选择" readonly></u-input></view>
      </view>
      <view class="row">
        <view class="left">状态</view>
        <view @click="showStatusPicker = true" class="right">
          <u-input class="my-input" v-model="status" placeholder="请选择" readonly></u-input>
        </view>
      </view>
      <view class="row">
        <view class="left">经办人</view>
        <view @click="showUserPicker = true" class="right">
          <u-input class="my-input" v-model="userName" placeholder="请选择" readonly></u-input>
        </view>
      </view>
      <view class="bottom">
        <button class="btn back" @click="reset">重置</button>
        <button class="btn" @click="submit">确认</button>
      </view>
    </view>
    <u-picker :show="showStatusPicker" :columns="typeList" keyName="name" @confirm="statusConfirm" @cancel="showStatusPicker = false"></u-picker>
    <u-picker :show="showUserPicker" :columns="userList" keyName="name" @confirm="userConfirm" @cancel="showUserPicker = false"></u-picker>
    <u-datetime-picker :show="showStartDate" v-model="defaultDate" mode="date" @cancel="showStartDate = false" @confirm="confirm"></u-datetime-picker>
    <u-datetime-picker :show="showEndDate" v-model="defaultDate" mode="date" @cancel="showEndDate = false" @confirm="endConfirm"></u-datetime-picker>
  </view>
</template>

<script>
import { formateDate } from '@/service/auth'
export default {
  name: 'filter',
  components: {},
  props: {
    userList: {
      type: Array,
      default: () => {
        return []
      },
    },
  },
  data() {
    return {
      showPop: false,
      showStartDate: false,
      showEndDate: false,
      endTime: '',
      startTime: '',
      defaultDate: Number(new Date()),
      status: '',
      typeList: [
        [
          { id: 1, name: '保存', code: 'SAVE' },
          { id: 2, name: '审核', code: 'PASS' },
        ],
      ],
      userName: '',
      showUserPicker: false,
      showStatusPicker: false,
      params: {},
    }
  },
  created() {},
  methods: {
    _cancel() {
      this._hide()
    },
    _show() {
      this.showPop = true
    },
    _hide() {
      this.showPop = false
    },
    reset() {
      this.startTime = ''
      this.endTime = ''
      this.status = ''
      this.userName = ''
      this.params = {}
      this.$emit('submit', { data: this.params })
      this._hide()
    },
    confirm(e) {
      console.log(e)
      this.startTime = formateDate(e.value)
      this.$set(this.params, 'startTime', this.startTime)
      this.showStartDate = false
    },
    endConfirm(e) {
      this.endTime = formateDate(e.value)
      this.$set(this.params, 'endTime', this.endTime)
      this.showEndDate = false
    },
    submit() {
      this._hide()
      this.$emit('submit', { data: this.params })
    },

    userConfirm(e) {
      console.log(e)
      this.$set(this.params, 'userId', e.value[0].id)
      this.userName = e.value[0].name
      this.showUserPicker = false
    },
    statusConfirm(e) {
      this.$set(this.params, 'orderStatus', e.value[0].code)
      this.status = e.value[0].name
      this.showStatusPicker = false
    },
  },
}
</script>
<style scoped lang="scss">
.container-mask {
  position: fixed;
  top: 0rpx;
  right: 0rpx;
  bottom: 0rpx;
  left: 0rpx;
  z-index: 9998;
  background-color: rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: all 0.3s ease;
  visibility: hidden;
}
.container-mask.show {
  visibility: visible;
  opacity: 1;
}
.container-pop {
  position: fixed;
  top: 0rpx;
  right: 0rpx;
  bottom: 0rpx;
  left: 0rpx;
  z-index: 9999;
  top: 58%;
  transition: all 0.3s ease;
  transform: translateY(100%);
  background-color: white;
  padding: 20rpx;
}
.container-pop.show {
  transform: translateY(0);
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20rpx;
  .right {
    flex: 1;
    margin: 0 20rpx;
  }
  .left {
    width: 150rpx;
  }
  .picker {
    flex: 1;
  }
}
.bottom {
  display: flex;
  align-items: center;
  position: absolute;
  height: 150rpx;
  bottom: 0;
  left: 0;
  right: 0;
  .btn {
    background-color: #2f6fef;
    flex: 1;
    height: 80rpx;
    line-height: 80rpx;
    color: white;
    border-radius: 50rpx;
    margin-left: 20rpx;
    margin-right: 20rpx;
    font-size: 28rpx;
  }
  .back {
    background-color: white;
    color: #888;
    border: 1rpx solid #cbd2de;
  }
}
</style>
